package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.EmailVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.PhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.SmsPhoneVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MemberRegisterVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordByEmailCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordBySmsCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberRegisterResultVO;
import com.ssy.lingxi.member.merchant.service.web.IMemberRegisterService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @menu 企业商城门户 - 会员注册
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-03
 */
@RestController
@RequestMapping("/member/register")
public class MemberRegisterController {

    @Resource
    private IMemberRegisterService memberRegisterService;

    /**
     * 检查手机号码是否被注册使用
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 检查结果
     */
    @RequestMapping(value = "/phone/check", method = RequestMethod.GET)
    public Wrapper<Void> checkPhoneRegistered(@RequestHeader HttpHeaders headers, @Valid PhoneVO phoneVO) {
        return memberRegisterService.checkPhoneRegistered(headers, phoneVO);
    }

    /**
     * 检查邮箱是否被注册使用
     * @param headers Http头部信息
     * @param emailVO 邮箱
     * @return 检查结果
     */
    @RequestMapping(value = "/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkEmailRegistered(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailVO emailVO) {
        return memberRegisterService.checkEmailRegistered(headers, emailVO);
    }

    /**
     * 发送注册时短信验证码
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 发送结果
     */
    @RequestMapping("/sms")
    public Wrapper<Void> sendRegisterSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsPhoneVO phoneVO) {
        return memberRegisterService.sendRegisterSmsCode(headers, phoneVO);
    }

    /**
     * 发送手机号找回密码时的短信验证码
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 发送结果
     */
    @RequestMapping("/psw/sms")
    public Wrapper<Void> sendResetPasswordSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid SmsPhoneVO phoneVO) {
        return memberRegisterService.sendResetPasswordSmsCode(headers, phoneVO);
    }

    /**
     * 根据短信验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/reset/sms")
    public Wrapper<Void> resetPasswordBySmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid ResetPasswordBySmsCodeVO codeVO) {
        return memberRegisterService.resetPasswordBySmsCode(headers, codeVO);
    }

    /**
     * 发送邮箱找回密码时的邮件
     * @param headers Http头部信息
     * @param emailVO 邮箱地址
     * @return 发送结果
     */
    @RequestMapping("/psw/email")
    public Wrapper<Void> sendResetPasswordEmail(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailVO emailVO) {
        return memberRegisterService.sendResetPasswordEmail(headers, emailVO);
    }

    /**
     * 根据邮箱验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping("/reset/email")
    public Wrapper<Void> resetPasswordByEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid ResetPasswordByEmailCodeVO codeVO) {
        return memberRegisterService.resetPasswordByEmailCode(headers, codeVO);
    }

    /**
     * 会员注册
     * @param headers Http头部信息
     * @param registerVO 接口参数
     * @return 注册结果
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public Wrapper<MemberRegisterResultVO> registerMember(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberRegisterVO registerVO) {
        return memberRegisterService.registerPlatformMember(headers, registerVO);
    }
}
